unit Con_Transportadora;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,
  Db, Dbtables, TFlatButtonUnit;

type
  TFrmCon_Transportadora = class(TFrmConsulta)
    Label1: TLabel;
    EdtNome: TEdit;
    DbgTransportadora: TDBGrid;
    btnGravar: TFlatButton;
    p_ordem: TRadioGroup;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure p_ordemClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Tran_codigo: string;
  end;

var
  FrmCon_Transportadora: TFrmCon_Transportadora;

implementation

uses Dm, Biblio, clsTransportadora, Cad_Transportadora, menu;

{$R *.DFM}

var
  TRansportadora: TTransportadora;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_Transportadora.BtnFecharClick(Sender: TObject);
begin
  Tran_codigo := tq.fieldbyname('Tran_codigo').asstring;
  tds.free;
  tq.free;
  inherited;
end;

procedure TFrmCon_Transportadora.EdtNomeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    EdtNome.setfocus;
  end;
end;

procedure TFrmCon_Transportadora.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  tds := TDataSource.create(FrmCon_Transportadora);
  tq := Tquery.create(FrmCon_Transportadora);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  p_ordem.setfocus;
end;

procedure TFrmCon_Transportadora.FazConsulta;
begin
  if EdtNome.text = '' then
    EdtNome.text := ' ';
  Transportadora := TTransportadora.Create;
  Transportadora.Consultar(tq, EdtNome.text, p_ordem.ItemIndex);
  tq.open;
  Transportadora.free;
  dbgTransportadora.DataSource := tds;
  dbgTransportadora.Refresh;
end;

procedure TFrmCon_Transportadora.btnGravarClick(Sender: TObject);
var
  f1: TFrmCad_Transportadora;
begin
  inherited;
  f1 := TFrmCad_Transportadora.Create(self);
  f1.btnC_Transportadora.Visible := False;
  f1.Tag := 1;
  f1.showModal;
  f1.Free;
  FazConsulta;
end;

procedure TFrmCon_Transportadora.p_ordemClick(Sender: TObject);
begin
  inherited;
  case TRadioGroup(Sender).ItemIndex of
    0: Label1.Caption := 'Nome';
    1: Label1.Caption := 'CNPJ/CPF';
  end;
end;

end.

